/**
 * data转字符串 年月日
 * @param {*} s
 */
export function formDateToString(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return year + '-' + month + '-' + day
}

export function formDateToString2(date) {
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return year + '/' + month + '/' + day
}
export function formDate(date) {
	if (date && date.indexOf('-') != -1) {
		date = date.replace(/-/g, '/')
	}
	let myDate = new Date(date)
	let year = myDate.getFullYear()
	let month = myDate.getMonth() + 1
	let day = myDate.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return year + '-' + month + '-' + day
}
/**
 * 获取当前月份的第一天
 * @returns {string}
 */
export function getCurrentMonthFirst() {
	const date = new Date()
	date.setDate(1)
	let month = parseInt(date.getMonth() + 1)
	if (month < 10) {
		month = '0' + month
	}
	return date.getFullYear() + '-' + month + '-01'
}
/**
 * 获取当前月份 不含日
 * @returns {string}
 */
export function getNowMonthNoDate() {
	const date = new Date()
	date.setDate(1)
	let month = parseInt(date.getMonth() + 1)
	if (month < 10) {
		month = '0' + month
	}
	return date.getFullYear() + '-' + month
}


/**
 * 获取当前月份的第一天
 * @returns {string}
 */
export function getCurrentMonthFirst1() {
	const date = new Date()
	let year = date.getFullYear()
	let month = parseInt(date.getMonth() + 1)
	let day = date.getDate() - 1
	if (day == 0) {
		month = month - 1
		if (month == 0) {
			month = 12
			year = year - 1
		}
		const date1 = new Date()
		date1.setTime(date1.getTime() - 24 * 60 * 60 * 1000)
	}
	day = 1
	if (day < 10) {
		day = '0' + day
	}
	if (month < 10) {
		month = '0' + month
	}
	return year + '-' + month + '-' + day
}

/**
 * 获取当前月份的最后一天
 * @returns {string}
 */
export function getCurrentMonthLast() {
	const date = new Date()
	let currentMonth = date.getMonth()
	let nextMonth = ++currentMonth
	let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1)
	let oneDay = 1000 * 60 * 60 * 24
	let lastTime = new Date(nextMonthFirstDay - oneDay)
	let month = parseInt(lastTime.getMonth() + 1)
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}

/**
 * 获取月份的第一天
 * @returns {string}
 */
export function getMonthFirst(time) {
	const date = new Date(time)
	let year = date.getFullYear()
	let day = date.getDate()
	let month = parseInt(date.getMonth() + 1)
	// console.log(month)
	if (day < 10) {
		day = '0' + day
	}
	if (month < 10) {
		month = '0' + month
	}
	return year + '-' + month + '-' + day
}

/**
 * 获取月份的最后一天
 * @returns {string}
 */
export function getMonthLast(time) {
	const date = new Date(time)
	let currentMonth = date.getMonth()
	let nextMonth = ++currentMonth
	let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1)
	let oneDay = 1000 * 60 * 60 * 24
	let lastTime = new Date(nextMonthFirstDay - oneDay)
	let month = parseInt(lastTime.getMonth() + 1)
	let day = new Date(new Date(date.getFullYear(),date.getMonth()).setDate(0)).getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}


/**
 * 获取当前月份的最后一天 减1(减去今天)
 * @returns {string}
 */
export function getCurrentMonthLast1() {
	const date = new Date()
	let currentMonth = date.getMonth()
	let nextMonth = ++currentMonth
	let nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1)
	let oneDay = 1000 * 60 * 60 * 24
	let lastTime = new Date(nextMonthFirstDay - oneDay)
	let month = parseInt(lastTime.getMonth() + 1)
	let day = date.getDate() - 1
	if (day == 0) {
		const date1 = new Date()
		date1.setTime(date1.getTime() - 24 * 60 * 60 * 1000)
		let month1 = parseInt(date1.getMonth() + 1)
		let day1 = date1.getDate()
		if (month1 < 10) {
			month1 = '0' + month1
		}
		if (day1 < 10) {
			day1 = '0' + day1
		}
		return date1.getFullYear() + '-' + month1 + '-' + day1
	}
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}

/**
 * 获取上个月的第一天
 * @returns {string}
 */
export function getUpMonthFirst() {
	const date = new Date()
	let year = date.getFullYear()
	let month = date.getMonth()
	if (month == 0) {
		month = 12
		year = year - 1
	}
	if (month < 10) {
		month = '0' + month
	}
	return year + '-' + month + '-01'
}

/**
 * 获取上个月的最后一天
 * @returns {string}
 */
export function getUpMonthLast() {
	const date = new Date()
	let year = date.getFullYear()
	let month = date.getMonth()
	if (month == 0) {
		month = 12
		year = year - 1
	}
	if (month < 10) {
		month = '0' + month
	}
	const myDate = new Date(year, month, 0);

	return year + '-' + month + '-' + myDate.getDate()
}


/**
 * 获取今年的第一天
 * @returns {string}
 */
export function getCurrentYearFirst() {
	const date = new Date()
	return date.getFullYear() + '-01-01'
}

/**
 * 获取今年的最后一天
 * @returns {string}
 */
export function getCurrentYearLast() {
	const date = new Date()
	let month = parseInt(date.getMonth() + 1)
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}

/**
 * 获取近一年
 * @returns {string}
 */
export function getUpYearFirst() {
	const date = new Date()
	let year = parseInt(date.getFullYear() - 1)
	let month = parseInt(date.getMonth() + 1)
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return year + '-' + month + '-' + day
}

/**
 * 获取近一年的前一天
 * @returns {string}
 */
export function getUpYearLast() {
	const date = new Date()
	let month = parseInt(date.getMonth() + 1)
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}


/**
 * 获取近一年的最后一天
 * @returns {string}
 */
export function getUpYearLast1() {
	const date = new Date()
	let month = parseInt(date.getMonth() + 1)
	let day = date.getDate()
	if (month < 10) {
		month = '0' + month
	}
	if (day < 10) {
		day = '0' + day
	}
	return date.getFullYear() + '-' + month + '-' + day
}


/**
 * picker获取选择日期转化
 * @returns {string}
 */
export function getFormDate(value) {
	return value.year + '-' + value.month + '-' + value.day
}